package com.link2room.rodimus.controller.manager;

import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.rodimus.facade.IPointFacadeService;
import com.link2room.sideswipe.permissionResouces.annotation.L2RPermissionResources;
import com.link2room.rodimus.dto.param.base.PointRuleBaseParamDto;
import com.link2room.rodimus.dto.result.base.PointRuleDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import static com.link2room.rodimus.constant.PermissionConstant.pointRule;
import static com.link2room.rodimus.constant.PermissionConstant.pointRules;


/**
 * Created by VegetaKo on 2017/3/20.
 */
@Api(tags = "积分管理")
@RestController
@RequestMapping("/manager/Points")
public class PointManagerController {

    @Resource
    private IPointFacadeService pointFacadeService;

    @ApiOperation(value = "积分规则列表", response = PointRuleDto.class)
    @ApiImplicitParams(value = {
    })
    @RequestMapping(value="/PointRules",method = RequestMethod.GET)
    @L2RPermissionResources(value = pointRules, name = "积分规则列表")
    public BaseResultDto pointRules(
    ) throws Exception {
        PointRuleBaseParamDto pointRuleBaseParamDto = new PointRuleBaseParamDto();
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        resDto.setQueryResult(pointFacadeService.getPointRules(pointRuleBaseParamDto));
        return resDto;
    }

    @RequestMapping(value = "/PointRules/PointRule", method = RequestMethod.GET)
    @L2RPermissionResources(value = pointRule, name = "积分规则详情")
    @ApiOperation(value = "积分详情", response = PointRuleDto.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "pointRuleCode",value = "积分规则代码",required = true)
    })
    public BaseResultDto pointRule(
            @RequestParam(value = "pointRuleCode" ,required = true) String pointRuleCode
            ) throws Exception {
        PointRuleBaseParamDto pointRuleBaseParamDto = new PointRuleBaseParamDto();
        pointRuleBaseParamDto.setPointRuleCode(pointRuleCode);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        resDto.setResultInfo(pointFacadeService.getPonitRuleByPointRuleCode(pointRuleBaseParamDto));
        return resDto;
    }
}
